//
//  WBNavViewController.swift
//  WCKweibo
//
//  Created by wukai on 17/2/25.
//  Copyright © 2017年 wuchunkai. All rights reserved.
//

import UIKit

class WBNavViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
    }
    
    
    ///重写push 方法，所有的方法都会电泳
    ///viewcontroller 是被push的控制器，设置它的左侧的返回按钮
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0 {
            
        //隐藏底部的的tabbar
        viewController.hidesBottomBarWhenPushed = true
        
        ///判断控制器的类型
        if let vc = viewController as? WBBaseViewController {
            
            var title = "返回"
            //判断控制器的级数
            if childViewControllers.count == 1 {
                //title 显示的标题
                title = childViewControllers.first?.title ?? "返回"
            }
            
            //取出自定义的navItem
            vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToparent), isBack: true)
        }

        }
        super.pushViewController(viewController, animated: true)
        
    }
    
    @objc private func popToparent(){
    popViewController(animated: true)
    
    }
    
}
